package com.yue.thread.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Test {

    public static void main(String[] args) {
         //new Test().fiexdPool();
        new Test().schedule();
    }
    public void fiexdPool(){
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        for(int i=0;i<999;i++){
            int finalI = i;
            executorService.submit(()->{
                System.out.println("当前值:"+ finalI +"当前线程+"+Thread.currentThread().getName());
            });
        }
    }
    public void newCache(){
        ExecutorService executorService = Executors.newCachedThreadPool();
        for(int i=0;i<999;i++){
            int finalI = i;
            executorService.submit(()->{
                System.out.println("当前值:"+ finalI +"当前线程+"+Thread.currentThread().getName());
            });
        }
    }
    public void Single(){
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        for(int i=0;i<999;i++){
            int finalI = i;
            executorService.submit(()->{
                System.out.println("当前值:"+ finalI +"当前线程+"+Thread.currentThread().getName());
            });
        }
    }
    public void schedule(){
        ExecutorService executorService = Executors.newScheduledThreadPool(2);
        for(int i=0;i<999;i++){
            int finalI = i;
            executorService.submit(()->{
                System.out.println("当前值:"+ finalI +"当前线程+"+Thread.currentThread().getName());
            });
        }
    }
}
